package com.bbs.manage.controller;

import com.bbs.common.CommonCode;
import com.bbs.common.ResponseResult;
import com.bbs.domain.Article;
import com.bbs.entity.PageResult;

import com.bbs.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/findAll")
    public List<Article> findAll(){
        return articleService.findAll();
    }

    @PostMapping("/findByPage")
    public PageResult<Article> findByPage(@RequestBody Map searchMap,int page,int size){
        return  articleService.findByPage(searchMap,page,size);
    }


    /**
     * 逻辑删除帖子
     * @param article
     * @return
     */
    @GetMapping("/delete")
    public ResponseResult delete (Article article) {

        articleService.delete(article);

        return new ResponseResult(CommonCode.SUCCESS);
    }

    /**
     * 修改帖子是否置顶
     *
     * @param article
     * @return
     */
    @RequestMapping("/updateIsTop")
    public ResponseResult updateIsTop(Article article) {

        articleService.updateIsTop(article);
        return new ResponseResult(CommonCode.SUCCESS);
    }
}
